// 创建multer实例，设置文件存储路径
const multer = require('multer');

// 配置multer
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
        cb(null, 'upload/');
    },
    filename: function (req, file, cb) {
        // file.originalname + 
        cb(null, Date.now() + '.' + file.mimetype.split('/')[1]);
    }
});

exports.upload = multer({
    storage: storage
});

// 定义uploadFileLocal函数，用于处理文件上传
exports.uploadFileLocal = async (req, res) => {
    // 处理文件上传逻辑
    // 多个文件上传
    const files = [];
    //如果为单个文件，将它放入数组
    if (req.file) {
        files.push(req.file);
    }
    else {
        files.push(...req.files);
    }
    res.send({
        status: 200,
        message: 'File uploaded successfully.',
        filePaths: files.map(file => `/uploads/${file.filename}`)
    });
};